import Vue from 'vue'
import Router from 'vue-router'

const Home = () => import('../view/home/Home.vue')              // 首页
const Login = () => import('../view/login/Login.vue')           // 登录
const Access = () => import('../view/access/Access.vue')        // 信息获取
const News = () => import('../view/home/news/News.vue')         // 山体资讯
const Interactive = () => import('../view/interactive/Interactive.vue')         // 参与互动
const Supervise = () => import('../view/supervise/Supervise.vue')               // 公众监督
const Call = () => import('../view/call/CallPage.vue')                          // 一键呼叫
const MyUpload = () => import('../view/MyUpload.vue')                           // 我的上传
const Notice = () => import('../view/home/notice/Notice.vue')                   // 公告
const Positioning = () => import('../view/positioning/Positioning.vue')         // 定位导航
const ScanCode = () => import('../view/scancode/ScanCode.vue')                  // 扫码看山
const Reporting = () => import('../view/reporting/Reporting.vue')               // 事件上报
const EventDetails = () => import('../view/reporting/eventdetails/EventDetails.vue')      // 事件详情 
const mounDetails = () => import('../view/moundetails/MounDetails.vue')        // 山体详情
const newsDetrails = () => import('../view/newsDetrails.vue') // 资讯详情
Vue.use(Router)


let router = new Router({
    mode: 'history',
    routes: [
        {
            path: '',
            redirect: 'Home',
            meta: {
                title: '跟路径',
                keepAlive: false //不需要被缓存的组件
            }
        },
        {
            path: '/home',
            name: 'Home',
            component: Home,
            meta: {
                title: '首页',
                keepAlive: false
            }
        },
        {
            path: '/login',
            name: 'Login',
            component: Login,
            meta: {
                title: '登录',
                keepAlive: true
            }
        },
        {
            path: '/access',
            name: 'Access',
            component: Access,
            meta: {
                title: '信息获取',
                keepAlive: false
            }
        },
        {
            path: '/news',
            name: 'News',
            component: News,
            meta: {
                title: '山体资讯',
                keepAlive: false
            }
        },
        {
            path: '/interactive',
            name: 'Interactive',
            component: Interactive,
            meta: {
                title: '参与互动',
                keepAlive: false
            }
        },
        {
            path: '/supervise',
            name: 'Supervise',
            component: Supervise,
            meta: {
                title: '公众监督',
                keepAlive: true
            }
        },
        {
            path: '/call',
            name: 'Call',
            component: Call,
            meta: {
                title: '一键呼叫',
                keepAlive: true
            }
        },
        {
            path: '/upload',
            name: 'MyUpload',
            component: MyUpload,
            meta: {
                title: '我的上传',
                keepAlive: true
            }
        },
        {
            path: '/notice',
            name: 'Notice',
            component: Notice,
            meta: {
                title: '公告',
                keepAlive: true
            }
        },
        {
            path: '/scanCode',
            name: 'ScanCode',
            component: ScanCode,
            meta: {
                title: '扫码看山',
                keepAlive: true
            }
        },
        {
            path: '/reporting',
            name: 'Reporting',
            component: Reporting,
            meta: {
                title: '事件上报',
                keepAlive: false
            }
        },
        {
            path: '/eventDetails',
            name: 'EventDetails',
            component: EventDetails,
            meta: {
                title: '事件详情',
                keepAlive: false
            }
        },
        {
            path: '/positioning',
            name: 'Positioning',
            component: Positioning,
            meta: {
                title: '定位导航',
                keepAlive: true
            }
        },
        {
            path: '/mounDetails',
            name: 'MounDetails',
            component: mounDetails,
            meta: {
                title: '济南山长',
                keepAlive: false
            }
        },
        {
            path: '/newsDetrails',
            name: 'newsDetrails',
            component: newsDetrails,
            meta: {
                title: '资讯详情',
                keepAlive: false
            }
        },
    ]

})

// 全局导航守卫
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title 
        if(to.query.type == 'yjfankui'){
            document.title = '意见反馈'
        }else if(to.query.type == 'hdcanyu'){
            document.title = '互动参与'
        } else if (to.query.type == 'sjshangbao'){
            document.title = '上报事件'
        }
    }
    next()
})

export default router